package org.canaan.aspose;

import com.aspose.cells.License;
import com.aspose.cells.Workbook;
import com.aspose.cells.WorkbookDesigner;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * excel 表格生成工具
 *
 * @author Canaan
 * @date 2017/9/14
 */
public final class CellsDemo {


    /**
     * 签名
     *
     * @return
     */
    public static boolean getLicense() {
        boolean result = false;
        InputStream is = CellsDemo.class.getClassLoader().getResourceAsStream("\\license.xml");

        License aposeLic = new License();
        try {
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    public static void main(String[] args) throws Exception {
        List<Map<String, Object>> users = new ArrayList<>();
        Map<String, Object> user = new HashMap<>();
        user.put("rn", 1);
        user.put("name", "张三");
        user.put("id_card", "4564845fas");
        user.put("age", 26);
        user.put("special", "唱歌");
        user.put("education", "高中");
        user.put("sta_date", "");
        user.put("end_date", "");
        user.put("province", "");
        user.put("registered_time", "");
        user.put("three_exam_names", "其他");
        user.put("duty", "组长");
        users.add(user);

        user = new HashMap<>();
        user.put("rn", 2);
        user.put("name", "王五");
        user.put("id_card", "e4564fds");
        user.put("age", 15);
        user.put("education", "高中");
        user.put("duty", "队长");
        user.put("special", "篮球");
        users.add(user);

        user = new HashMap<>();
        user.put("rn", 3);
        user.put("name", "钱七");
        user.put("id_card", "dartasdf");
        user.put("age", 54);
        user.put("education", "大学");
        user.put("three_exam_names", "其他");
        user.put("special", "篮球");
        users.add(user);

        Workbook wb = new Workbook("E:\\Project\\IdeaProjects\\cutil\\lib\\组人员信息表.xls");

        WorkbookDesigner designer = new WorkbookDesigner();
        designer.setWorkbook(wb);
        designer.setDataSource("company", "轩亚科技");
        designer.setDataSource("teamName", "研发部");
        designer.setDataSource("exportTime", "2017-02-03");
        designer.setDataSource("user", new MapCellsTable(users));
        designer.process();
        wb.save("E:\\Download\\test1.xls");
        System.out.println("===完成==");
    }


}
